const asyncHandler = require("../utils/asyncHandler");
const { success, error } = require('../utils/response')

// 当前用户信息
exports.getMe = asyncHandler(async (req, res) => {
    return success(res, { user: req.user })
});

// 更新当前用户
exports.updateMe = asyncHandler(async (req, res) => {
    const { username, bio, avatarUrl } = req.body;
    if (username !== undefined) req.user.username = username;
    if (bio !== undefined) req.user.bio = bio;
    if (avatarUrl !== undefined) req.user.avatarUrl = avatarUrl;
    await req.user.save();
    return success(res, { user: req.user }, '更新成功')
});
